package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusScholartyrant;
import com.meida.module.bus.provider.service.BusSubjectService;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BusScholarTyrantGetHandler implements GetInterceptor {

    @Autowired
    private BusSubjectService busSubjectService;

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.clear();
        cq.select(BusScholartyrant.class, "scholartyrantId", "subjectInfo", "selfIntroduction", "tags", "state", "approvalInfo", "createTime");
        cq.select(AppUser.class, "userName");
        cq.eq(BusScholartyrant.class, "state");
        cq.eq(AppUser.class, "userName");
        cq.createJoin(AppUser.class).setMainField("scholartyrantId").setJoinField("userId");
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        String subjectIds = map.get("subjectInfo");
        List<String> subjectTitles = busSubjectService.selectSubjectTitles(subjectIds);
        map.put("subjectTitles", subjectTitles);
    }
}
